package spring.cloud.tasks.executor.utils;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j
@Setter
@Getter
public class ExecutorServiceUtil {
    public static void shutdownNow(java.util.concurrent.ExecutorService executorService) {
        try {
            if (executorService != null && !executorService.isTerminated()) {
                executorService.shutdownNow();
                try {
                    while (!executorService.awaitTermination(1, TimeUnit.SECONDS)) {
                        executorService.shutdownNow();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
